const isWechat =function(){
	return String(navigator.userAgent.toLowerCase().match(/MicroMessenger/i)) === 'micromessenger';
}
const wechatAppid = function() {
  return 'wx6c34d9729972a651';
}
const payed = function(data){
	WeixinJSBridge.invoke('getBrandWCPayRequest', data, function(respay) {
		if (respay.err_msg === "get_brand_wcpay_request:ok") {
			/* uni.showModal({
				title: '中天优速递',
				content: '您已支付成功，是否现在开具发票',
				success: function (res) {
					if (res.confirm) {
						uni.navigateTo({
							url: "/pages/mine/ticket/index",
						});
					} else if (res.cancel) {
						location.reload()
					}
				}
			}); */
			uni.showToast({
				title:"支付成功",
				icon:"none",
				duration:2000
			})
		} else if (respay.err_msg === "get_brand_wcpay_request:cancel") {
			uni.showToast({
				title:"取消支付",
				icon:"none",
				duration:2000
			})
		} else if (respay.err_msg === "get_brand_wcpay_request:fail") {
			uni.showToast({
				title:"支付失败",
				icon:"none",
				duration:2000
			})
		}
	}, function(err) {
		uni.showToast({
			title:err,
			icon:"none",
			duration:2000
		})
	})
}
/**
 * http请求
 * action 方法名
 * data  传输数据
 * Method 请求方式 GET POST
 */
const Requests = function (action,data,Method='GET',event) {
	var headers = {
		'content-type': 'application/json' // 默认值
	}
	if (Method == 'POST') {
		headers = {
			'content-type': 'application/x-www-form-urlencoded' // 默认值
		}
	}
	uni.request({
		url: config.requestUrl + action,
		method:Method,
		header:headers,
		data: data,
		success(res) {
			if (res.data.status == 100) {
				return event(res.data);
			}else {
				uni.showToast({
					title: res.data.msg,
					icon:'none'
				})
			}
		},fail() {
			uni.showToast({
			  title: '网络异常',
			  icon: 'none',
			  duration: 2000
			})
		}
	})
}
export default {
	isWechat,
	wechatAppid,
	payed,
	Requests 
}
